﻿using Levfier.GUI.EditorControls.Parameters;
using Levfier.GUI.Status;
using Levfier.Proccessors.Parameters;
using System.Windows.Controls;

namespace Levfier.GUI.EditorControls
{
    /// <summary>
    /// MainParameterControl.xaml の相互作用ロジック
    /// </summary>
    public partial class MainParameterControl : UserControl
    {
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainParameterControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// ステータスを復元する
        /// </summary>
        /// <param name="param"></param>
        /// <param name="status"></param>
        public void LoadStatus(ProccessParameter param, MainParameterStatus status)
        {
            KnobControl knob = new KnobControl();
            knob.LoadStatus(param, status);
            knob.Delete += Knob_Delete;
            this.mainParameterStack.Children.Add(knob);
        }

        /// <summary>
        /// パラメータがドロップされたときの動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StackPanel_Drop(object sender, System.Windows.DragEventArgs e)
        {
            IParameterHolder holder = e.Data.GetData(typeof(IParameterHolder)) as IParameterHolder;

            if (null != holder)
            {
                ProccessParameter param = holder.ProccessParameter;
                //this.RegisterParam(param);
                KnobControlCreateWindow window = new KnobControlCreateWindow(param, this.mainParameterStack);
                window.ShowDialog();
                window.Activate();
            }
            else
            {
                //debugText.Text += "miss";
            }
        }

        /// <summary>
        /// パラメータを登録する
        /// </summary>
        /// <param name="param"></param>
        private void RegisterParam(ProccessParameter param)
        {
            //ParameterSlider slider = new ParameterSlider();
            //slider.RegisterParam(param);
            KnobControl knob = new KnobControl();
            knob.RegisterParam(param);
            knob.paramName.Text = param.Name;
            knob.Delete += Knob_Delete;
            this.mainParameterStack.Children.Add(knob);
        }

        /// <summary>
        /// ノブ削除
        /// </summary>
        /// <param name="sender"></param>
        private void Knob_Delete(object sender)
        {
            this.mainParameterStack.Children.Remove(sender as System.Windows.UIElement);
        }
    }
}
